package game.editer.ui;

import game.editer.view.AtlasOffestEditerView;
import game.editer.view.CreateEffectPreviewView;
import game.editer.config.HitDataConfig;
import hx.events.MouseEvent;

/**
 * 特效属性选择输入支持
 */
class EffectSelectInput extends BaseAttributeInput {
	var button = new Button();

	override function onInit() {
		super.onInit();
		button.text = "选择";
		button.width = 90;
		button.addEventListener(MouseEvent.CLICK, (e) -> {
			var view = new CreateEffectPreviewView("设置击中特效", 800, 600);
			this.topView.addChild(view);
			view.onCreateEffect = (effect) -> {
				this.value = effect.name;
				this.onAttributeChange(this);
			}
		});
		this.addChild(button);
		var edit = new CommonButton("UIAtlas:edit");
		this.addChild(edit);
		edit.addEventListener(MouseEvent.CLICK, (e) -> {
			if (this.value != null && this.value != "") {
				var view = new AtlasOffestEditerView("精灵图属性编辑", 800, 700);
				view.edit(button.text);
				this.topView.addChild(view);
			}
		});
	}

	override function set_value(value:Dynamic):Dynamic {
		if (value != null && value != "") {
			this.button.text = value;
		} else {
			this.button.text = "选择";
		}
		return super.set_value(value);
	}
}
